import {Dialog} from "./Dialog";
import {Button} from "./Button";
/**
 * Created by quxiangqian on 2018/6/15.
 */
export class WindowManager extends React.Component{

    state={
        win:[]

    }

    alert=(text,ok)=>{
        let a={}
        this.state.win.push(<Dialog  bind={a} title="提示" show={true}>
            <div class="alert">
                <p>{text}</p>
                <div className="control" style={{textAlign:"center"}}>
                <Button onClick={()=>{
                    if(ok){
                        ok();
                    }
                    a.t.hide();
                }} css="btn-primary" >关闭</Button>
                </div>
            </div>
            </Dialog>
        );
        this.setState({load:true});

    }

    confirm=(text,success,canel)=>{
        let index=this.state.win.length;
        let a={}
        let dialog=<Dialog title="系统确认" bind={a} show={true}>
            <div class="alert">
            <p>{text}</p>
                <div className="control" style={{textAlign:"right"}}>
            <Button css="btn-primary" onClick={(e)=>{
                if(success){
                    success();
                }
                a.t.hide();
            }}>确认</Button>
            <Button onClick={(e)=>{
                if(canel){
                    canel();
                }
                a.t.hide();
            }}>关闭</Button>
            </div>
            </div>
        </Dialog>;

        this.state.win.push(dialog);
        this.setState({load:true});
    }



    render(){
        return <div>{this.state.win.map((w)=>w)}</div>;
     }
}